package com.tencent.sr.iris.basic.saas.dependency;

import com.alibaba.fastjson.JSON;
import com.tencent.sr.iris.basic.saas.common.utils.HttpUtils;
import com.tencent.sr.iris.basic.service.interfaces.client.WxClient;
import com.tencent.sr.iris.basic.service.interfaces.constant.ApiSourceEnum;
import com.tencent.sr.iris.basic.service.interfaces.request.GetWxQrCodeRequest;
import com.tencent.sr.iris.basic.service.interfaces.response.GetWxQrCodeResponse;
import com.tencent.sr.iris.basic.service.interfaces.response.QrCodeBase64Response;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.springbootstarter.authtoken.localbean.AppUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author nixiaolin
 * @date 2022/11/13 15:31
 */
@Slf4j
@Component
public class WxDependency {

    @Resource
    private WxClient wxClient;

    @Resource
    private AppUser appUser;

    public QrCodeBase64Response getWxQrCodeBase64(GetWxQrCodeRequest request) {
        request.setUid(appUser.getUid());
        request.setUnionId(appUser.getWxUnionId());
        request.setApiSource(ApiSourceEnum.IRIS.getCode());
        log.info("WxDependency.getWxQrCode调用，入参：{}", JSON.toJSONString(request));
        HttpResult<QrCodeBase64Response> wxQrCode = wxClient.getWxQrCodeBase64(request);
        return HttpUtils.handleResult(wxQrCode);
    }

    public GetWxQrCodeResponse getWxQrCodeResponse(GetWxQrCodeRequest request) {
        request.setUid(appUser.getUid());
        request.setUnionId(appUser.getWxUnionId());
        request.setApiSource(ApiSourceEnum.IRIS.getCode());
        log.info("WxDependency.getWxQrCode调用，入参：{}", JSON.toJSONString(request));
        HttpResult<GetWxQrCodeResponse> wxQrCode = wxClient.getWxQrCode(request);
        return HttpUtils.handleResult(wxQrCode);
    }

}
